package com.heima.comment.controller;

import com.heima.comment.pojos.ApCommentLike;
import com.heima.comment.pojos.CommentSaveDto;
import com.heima.comment.service.ApCommentLikeService;
import com.heima.comment.service.ApCommentService;
import com.heima.model.comment.dtos.CommentDto;
import com.heima.model.comment.dtos.CommentLikeDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文章评论Controller
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {
    @Autowired
    private ApCommentService apCommentService;

    @Autowired
    private ApCommentLikeService apCommentLikeService;

    /**
     * 保存评论
     *
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody CommentSaveDto dto) {
        log.info("保存评论入参:{}", dto);
        //调用service
        return apCommentService.saveComment(dto);
    }


    /**
     * 查询评论列表
     *
     * @return
     */
    @PostMapping("/load")
    public ResponseResult loadComment(@RequestBody CommentDto dto) {
        log.info("查询评论列表入参:{}",dto);
        //调用service
         return apCommentService.loadComment(dto);
    }


    /**
     * 评论点赞
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult commentLike(@RequestBody CommentLikeDto dto) {
        log.info("评论点赞入参:{}", dto);
        //调用service
        return apCommentLikeService.commentLike(dto);
    }
}
